package com.chuan.it_market.config;


import com.chuan.it_market.consts.GoodsConsts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {



    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/admin").setViewName("seller/seller-admin");
        registry.addViewController("/admin2").setViewName("buyer/buyer-admin");

        registry.addViewController("seller/goods/goodsAddPre").setViewName("seller/goods/goods-addpre");
        registry.addViewController("/seller/goods/goodsList").setViewName("seller/goods/goods-list");

        registry.addViewController("/user/seller/password").setViewName("seller/center/seller-password");
        registry.addViewController("/user/buyer/password").setViewName("buyer/center/buyer-password");


        registry.addViewController("/bookBorrowAdd").setViewName("bookBorrowAdd");
        registry.addViewController("/bookBorrowEdit").setViewName("bookBorrowEdit");
        registry.addViewController("/bookReBorrow").setViewName("bookReBorrow");
        registry.addViewController("/bookReBorrowEdit").setViewName("bookReBorrowEdit");
        registry.addViewController("/bookReturn").setViewName("bookReturn");
        registry.addViewController("/bookReader").setViewName("bookReader");
        registry.addViewController("/bookStat").setViewName("bookStat");
    }
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*")
                .allowedMethods("GET","HEAD","POST","PUT","DELETE")
                .allowCredentials(false).maxAge(3600);

    }






    @Override
    public void addResourceHandlers(ResourceHandlerRegistry resourceHandlerRegistry)
    {
        Logger logger = LoggerFactory.getLogger(WebMvcConfig.class);
        String docPath= GoodsConsts.getConfigUploadPath();
        logger.info("图片上传路径为："+docPath);
        resourceHandlerRegistry.addResourceHandler("/upload/**").addResourceLocations(docPath);
    }


}
